﻿using System;
using System.Collections.Generic;
using System.Data;
using System.Text;
using WAD.WEB.AppCode;
using WAD.DAL;
using WAD.Model;
using System.Web.Script.Serialization;
using WAD.Model.JSON.Shared;

namespace WAD.WEB.Client2
{
    public partial class FC_Detail : WebBase
    {
        int article_id;
        protected string title, content, url, type, logo, date, click, phone, advert_ids, authorId = "0";
        protected StringBuilder sbAdvert = new StringBuilder();

        protected String host;

        protected void Page_Load(object sender, EventArgs e)
        {
            host = "http://" + Request.Url.Host.ToString();
            article_id = Parse.Int("article_id", 0);
            title = Parse.String("url_title", "");
            url = Parse.String("url", "");
            type = Parse.String("type", "");

            if (article_id > 0)
            {
                Dictionary<string, object> model = DAOFCArticle.Get("fc_article", "id=" + article_id);

                if (model != null)
                {
                    title = Convert.ToString(model["title"]);
                    url = Convert.ToString(model["url"]);
                    logo = Convert.ToString(model["logo"]);
                    content = Convert.ToString(model["content"]);
                    date = Convert.ToString(model["date"]);
                    authorId = Convert.ToString(model["user_id"]);
                }
            }

            if (string.IsNullOrEmpty(logo))
                logo = host + "/client/img/cover.jpg";

            if (logo.ToLower().IndexOf("http") == -1)
                logo = host + logo;  //外部链接的图片(从正文里抓取的)
        }

        protected string GetIntro(int len)
        {
            if (string.IsNullOrEmpty(content))
                return "";
            string intro = QD.WX.Utill.Util.RemoveHtml(content);
            if (intro.Length > len)
                return intro.Substring(0, len);
            return intro;
        }


        /// <summary>
        /// 获取分享信息(APP用)
        /// </summary>
        /// <param name="len"></param>
        /// <returns></returns>
        protected string GetShared(int len, string callback)
        {
            MSharedUrl model = new MSharedUrl();
            model.title = title;
            model.description = GetIntro(len);
            model.logo = logo;
            model.url = url;      //分享的完整网址
            model.shareList = new List<string>();
            model.shareList.Add("weixin_circle");
            model.callback = callback;
            if (model.description.Length == 0)
            {
                model.description = title;
            }
            JavaScriptSerializer json = new JavaScriptSerializer();
            return "callback://FCShared?" + Server.UrlEncode(json.Serialize(model));
        }
    }
}